package listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
@WebListener
public class ABCListener implements ServletContextListener, ServletContextAttributeListener, 
HttpSessionListener, HttpSessionAttributeListener, HttpSessionIdListener, ServletRequestListener, 
ServletRequestAttributeListener {
    public ABCListener() {
    	System.out.println("TestListener构造方法运行了");
    }
    public void contextInitialized(ServletContextEvent sce)  { 
    	System.out.println("ServletContext全局对象被WEB服务器初始化了");
    }
    public void contextDestroyed(ServletContextEvent sce)  { 
    	System.out.println("ServletContext全局对象被WEB服务器销毁了");
}
//ServletContextAttributeListener
    public void attributeAdded(ServletContextAttributeEvent scae)  { 
    	System.out.println("向ServletContext对象绑定名是"+scae.getName() +"值是" + scae.getValue()+"的属性");
    }
    public void attributeReplaced(ServletContextAttributeEvent scae)  { 
    	System.out.println("ServletContext的属性名" + scae.getName() + "的值改变了，原来的值是" + scae.getValue());
    }
    public void attributeRemoved(ServletContextAttributeEvent scae)  { 
    	 System.out.println("ServletContext的属性" + scae.getName()+"被解除绑定");
    }
    //ServletRequestListener
    public void requestInitialized(ServletRequestEvent sre)  { 
    	System.out.println("来自" + sre.getServletRequest().getRemoteAddr() + "的request请求对象被创建了");
    }
    public void requestDestroyed(ServletRequestEvent sre)  { 
    	System.out.println("来自" + sre.getServletRequest().getRemoteAddr() + "的request请求对象被删除了");
    }
	//ServletRequestAttributeListener
    public void attributeAdded(ServletRequestAttributeEvent srae)  { 
    	System.out.println("向request请求对象绑定名是"+srae.getName() +"值是" + srae.getValue()+"的属性");
    }
    public void attributeReplaced(ServletRequestAttributeEvent srae)  { 
    	System.out.println("request请求对象的属性名" + srae.getName() + "的值改变了，原来的值是" + srae.getValue());
    }
    public void attributeRemoved(ServletRequestAttributeEvent srae)  { 
    	System.out.println("request请求对象的" + srae.getName() + "属性被解除绑定了");
    }
    //HttpSessionListener
    public void sessionCreated(HttpSessionEvent se)  { 
    	 System.out.println(se.getSession().getId()+"的Session被创建");
    }
    public void sessionDestroyed(HttpSessionEvent se)  { 
         System.out.println(se.getSession().getId()+"的Session被销毁");
    }
	//HttpSessionAttributeListener
    public void attributeAdded(HttpSessionBindingEvent se)  { 
    	System.out.println("向session绑定了属性名是" + se.getName() + "的属性");
    }	
    public void attributeReplaced(HttpSessionBindingEvent se)  { 
    	System.out.println("session属性名"+ se.getName() +"的值改变了，原来的值是" + se.getValue());
    }
    public void attributeRemoved(HttpSessionBindingEvent se)  { 
    	System.out.println("session的属性" + se.getName() + "被解绑了");
    }
    //HttpSessionIdListener
    public void sessionIdChanged(HttpSessionEvent arg0, String arg1)  { 
    	 System.out.println(arg0.getSession().getId()+"的SessionID被修改为：" + arg1);
    }	
}
